from flask import Blueprint, session, redirect, url_for, request

# 1. 创建蓝图
admin_blu = Blueprint("admin", __name__, url_prefix="/admin")


# 请求钩子判断用户是否登陆
@admin_blu.before_request
def id_user_login():
    is_admin = session.get("is_admin")
    if not is_admin and not request.url.endswith("admin/login"):
        return redirect(url_for("home.index"))


# 4. 关联视图函数
from .views import *
